package screen.component
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.net.navigateToURL;
	import flash.net.sendToURL;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import helper.Services;
	import helper.ValueObject;
	import screen.SacombankScreen;
	/**
	 * ...
	 * @author ...
	 */
	public class Header extends UI
	{
		private var _deposit_popup : MovieClip;
		private static var instance : Header;
		private var _service:Services;
		private var _deposit_loader:URLLoader;
		
		public function Header() 
		{
			if(!instance){
				instance = this;
			}			
			init();			
		}
		public static function getInstance(): Header{
			if(!instance){
				instance = new Header();
			}
			return instance;
		}
		public function init():void {
			_service = Services.getInstance();
			_deposit_loader = new URLLoader();
		}
		public function showDepositPopup(str:String ):void {
			_deposit_popup = ValueObject.S2_RESOURCE.getExportedAsset("deposit") as MovieClip;
			popupInit(_deposit_popup);
			with (_deposit_popup) {
				buttonImageInit(yesBtn);
				buttonImageInit(noBtn);
				MovieClip(yesBtn).addEventListener(MouseEvent.CLICK, getDeposit);
				MovieClip(noBtn).addEventListener(MouseEvent.CLICK,exit);
			}
			_deposit_popup.timeTf.text = "" + str;
			popupShow(_deposit_popup);
			
		}
		private function getDeposit(e:MouseEvent):void {
			_deposit_loader.addEventListener(Event.COMPLETE,getDepositComplete);
			_deposit_loader.addEventListener(IOErrorEvent.IO_ERROR,getDepositError);
			_deposit_loader.load(_service.getDepositRequest());
		}
		
		private function getDepositComplete(e:Event):void {
			_deposit_loader.removeEventListener(Event.COMPLETE,getDepositComplete);
			_deposit_loader.removeEventListener(IOErrorEvent.IO_ERROR, getDepositError);
			navigateToURL(new URLRequest("http://tietkiemphudong.vn/"),"_parent");
		}
		private function getDepositError(e:IOErrorEvent):void{
			_deposit_loader.removeEventListener(Event.COMPLETE,getDepositComplete);
			_deposit_loader.removeEventListener(IOErrorEvent.IO_ERROR, getDepositError);
		}
		private function exit(e:MouseEvent):void {
			navigateToURL(new URLRequest("http://tietkiemphudong.vn/"),"_parent");
		}
		
		public function gotoBaby():void {
			navigateToURL(new URLRequest("http://www.tietkiemphudong.vn/chuyen-con-tre/"),"_parent");
		}
		public function goHome():void {
			navigateToURL(new URLRequest("http://www.tietkiemphudong.vn"),"_parent");
		}
		public function gotoIntro():void {
			navigateToURL(new URLRequest("http://www.tietkiemphudong.vn/gioi-thieu/"),"_parent");
		}
	}

}